`
https://leetcode.cn/problems/linked-list-in-binary-tree/
`

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {ListNode} head
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSubPath = function (head, root) {
  // base case
  if (head === null) return true
  if (root === null) return false
  // 当找到一个二叉树节点的值等于链表头结点时
  if (head.val === root.val) {
    // 判断是否能把链表嵌进去
    if (check(head, root)) {
      return true
    }
  }
  // 继续去遍历其他节点尝试嵌入链表
  return isSubPath(head, root.left) || isSubPath(head, root.right)
};

// 检查是否能够将链表嵌入二叉树
function check(head, root) {
  if (head === null) return true
  if (root === null) return false

  if (head.val === root.val) {
    // 在子树上嵌入子链表
    return check(head.next, root.left) || check(head.next, root.right)
  }

  return false
};